/*
 * Copyright 2011 The Rusted Roof, LLC.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package org.proteusframework.core.spi;

import org.proteusframework.core.api.model.IPlugin;
import org.proteusframework.core.api.model.IVersion;
import org.proteusframework.core.api.model.IVersionDescriptor;
import org.proteusframework.core.base.NoSuchVersionException;

import java.util.Collection;

/**
 * Abstract factory used to create specific {@link IPlugin} instances that can support a specific
 * {@link IVersionDescriptor}.
 *
 * @author Tacoma Four
 */
public interface IRegistrar extends IAbstractProvider
{
    /**
     * Create the <code>IPlugin</code> instance that matches the given version descriptor.
     *
     * @param versionDescriptor Version descriptor
     * @param expectedInterface Expected interface; must extend IPlugin
     * @param <T>               Specifies the type of plugin being created
     * @return Non-null plugin instance
     * @throws org.proteusframework.core.base.NoSuchVersionException
     *          when either the version is unsupported, or when the
     *          version is supported but cannot be contractually refined to meet the requested mandatory configuration
     *          property restrictions defined by the version descriptor
     */
    <T extends IPlugin> T create(IVersionDescriptor versionDescriptor, Class<T> expectedInterface)
            throws NoSuchVersionException;

    /**
     * Determines if the registrar supports the given API version.
     *
     * @param version Version to check
     * @return true, if the registrar is capable of producing an <code>IPlugin</code> instance that supports the
     *         given API version
     */
    boolean supportsVersion(IVersion version);

    /**
     * Provides a definite, immutable collection of API versions supported by the registrar.
     *
     * @return Version collection
     */
    Collection<IVersion> supportedVersions();
}
